package com.website.view.component
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;

	public class PicItem extends Sprite
	{
		private var _imageLoader:Loader;
		public function PicItem()
		{
			
		}
		
		public function loadImage(url:String) : void
		{
			if(_imageLoader == null)
			{
				_imageLoader = new Loader();
			}
			_imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded, false, 0, true);
			_imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onImageError, false, 0, true);
			var request:URLRequest = new URLRequest(url);
			var context:LoaderContext = new LoaderContext();
			context.checkPolicyFile = true;
			_imageLoader.load(request, context);
		}
		
		public function onImageLoaded(event:Event) : void
		{
			var bit:Bitmap = _imageLoader.content as Bitmap;
			bit.width = 145;
			bit.height = 145;
			addChild(bit);
		}
		
		public function onImageError(event:Event) : void
		{
			trace("Load error: ");
		}
	}
}